import { ElMessage } from "element-plus";

// message.js
/**
 * @Description: 重写message挂载，实现 Class 的私有属性
 * @param { String } options => 消息内容
 * @param { Boolean } single => 是否只显示一个
 */

const showMessage = Symbol("showMessage");

class DomMessage {
  success(options, single = false) {
    this[showMessage]("success", options, single);
  }
  warning(options, single = false) {
    this[showMessage]("warning", options, single);
  }
  info(options, single = false) {
    this[showMessage]("info", options, single);
  }
  error(options, single = true) {
    this[showMessage]("error", options, single);
  }

  [showMessage](type, options, single) {
    if (single) {
      // 判断是否已存在Message
      if (document.getElementsByClassName("el-message--error").length === 0) {
        ElMessage[type](options);
      }
    } else {
      ElMessage[type](options);
    }
  }
}

// 默认导出 私有 Message 组件
export default new DomMessage();
